package io.hxci.modules.zhangcong.controller;


import io.hxci.common.utils.PageUtils;
import io.hxci.common.utils.R;
import io.hxci.modules.sys.shiro.ShiroUtils;
import io.hxci.modules.zhangcong.domain.Zcuser;
import io.hxci.modules.zhangcong.service.ZcuserService;
import io.hxci.modules.zhangcong.service.impl.ZcuserServiceImpl;
import org.apache.commons.lang.RandomStringUtils;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;
import java.util.Map;

//类----->属性---->方法
@RestController //注解
@RequestMapping("zc")
public class ZCController {
    @Autowired
    ZcuserService zcservice ;
    //面向对象 类 对象 方法 属性 方法的调用 传参 接口 和 继承 多态
    // 集合
   // 方法  参数 返回值
    //接收一个网址找类找方法
    @RequestMapping("zcquery")
   @RequiresPermissions("zc:zcuser:zcquery")
    public R zcquery(@RequestParam Map<String, Object> zcparams){
        PageUtils zcpage = zcservice.queryPage(zcparams);
        return R.ok().put("page", zcpage);
    }

    //接收一个网址找类找方法
    @RequiresPermissions("zc:zcuser:zcdel")
    @RequestMapping("zcdel")
    public R zcdel(@RequestBody Long[] userIds){
        zcservice.removeByIds(Arrays.asList(userIds));
        return R.ok();
    }

    //接收一个网址找类找方法
    @RequestMapping("zcedit/{userId}")
    @RequiresPermissions("zc:zcuser:zcupdate")
    public R zcedit(@PathVariable("userId") Long userId){
        Zcuser zcuser = zcservice.getById(userId);
        return R.ok().put("zcuser", zcuser);
    }


    //接收一个网址找类找方法
    @RequestMapping("zcadd")
    @RequiresPermissions("zc:zcuser:zcadd")
    public R zcadd(@RequestBody Zcuser zcuser){
//        String salt = RandomStringUtils.randomAlphanumeric(20);
//        zcuser.setSalt(salt);
//        zcuser.setPassword(ShiroUtils.sha256(zcuser.getPassword(), zcuser.getSalt()));
        zcservice.saveOrUpdate(zcuser);
        return R.ok();
    }



}
